package org.rufolfheszele.andpixelbyandpixel.configuration;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * This class holds the proxy related configuration data
 *
 * @author Rudolf Heszele heszele@gmail.com
 * @version 2.0
 * @since 2012-05-19
 */
public class ProxyConfiguration
{
		/**
		 * The only constructor takes the XML node and reads every data into its data members
		 *
		 * @param node The XML node containing the network configuration
		 */
		public ProxyConfiguration(Node node)
		{
			NodeList children = node.getChildNodes();

			mNode = node;
			for(int i = 0; i < children.getLength(); ++i)
			{
				Node childNode = children.item(i);
				
				if(true == childNode.getNodeName().equals("use-proxy"))
				{
					if(true == childNode.getChildNodes().item(0).getNodeValue().equals("yes"))
						mUseProxy = true;
					else
						mUseProxy = false;
				}
				if(true == childNode.getNodeName().equals("proxy-address"))
				{
					mProxyAddress = new ProxyAddress(childNode);
				}
			}
		}
		
		public boolean useProxy()
		{
			return mUseProxy;
		}
		
		public void setUseProxy(boolean useProxy)
		{
			String nodeContent;

			mUseProxy = useProxy;
			if(true == mUseProxy)
				nodeContent = "yes";
			else
				nodeContent = "no";
			Configuration.updateNodeContent(mNode, "use-proxy", nodeContent, null);
		}
		
		ProxyAddress getProxyAddress()
		{
			return mProxyAddress;
		}

		private boolean mUseProxy			= false;
		private ProxyAddress mProxyAddress	= null;
		private Node mNode					= null;
}
